package com.nhii.appframe.mvp.ui.activity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.gyf.immersionbar.ImmersionBar;
import com.jess.arms.base.BaseNoTitleActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.nhii.appframe.di.component.DaggerSplashComponent;
import com.nhii.appframe.mvp.contract.SplashContract;
import com.nhii.appframe.mvp.presenter.SplashPresenter;
import com.nhii.base.common.core.ProjectConstants;
import com.nhii.base.common.utils.SPUtils;
import com.nhii.mc.R;


import static com.jess.arms.utils.Preconditions.checkNotNull;


/**
 * ================================================
 * author : Alex
 * e-mail : xys9786@outlook.com
 * version: 1.0
 * Description:  启动页
 * <p>
 * Created by MVPArmsTemplate on 05/05/2020 08:05
 * ================================================
 */
public class SplashActivity extends BaseNoTitleActivity<SplashPresenter> implements SplashContract.View {

    private String isLogin;

    @Override
    public void setupActivityComponent(@NonNull AppComponent appComponent) {
        DaggerSplashComponent //如找不到该类,请编译一下项目
                .builder()
                .appComponent(appComponent)
                .view(this)
                .build()
                .inject(this);
    }

    @Override
    public int initView(@Nullable Bundle savedInstanceState) {
        return R.layout.activity_splash; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
    }

    @Override
    protected void onNetReload(View v) {

    }

    @Override
    public void initData(@Nullable Bundle savedInstanceState) {
        ImmersionBar.with(this).fullScreen(true).init();

        SharedPreferences sharedPreferences = getSharedPreferences(SPUtils.FILLNAME,0);

        if (sharedPreferences!=null){
            isLogin = (String) SPUtils.get(ProjectConstants.COMMON_ISLOGIN,"false");
        }

        if (isLogin.equals("false")){
            new Handler().postDelayed(new Runnable(){

                public void run() {
                    launchActivity(new Intent(SplashActivity.this,LoginActivity.class));
                    finish();
                }

            }, 0);
        }else{
            new Handler().postDelayed(new Runnable(){

                public void run() {
                    launchActivity(new Intent(SplashActivity.this, MainActivity.class));
                    finish();
                }

            }, 1000);

        }
    }



}
